package com.ideawedo.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws InterruptedException
    {
    	//两个nio线程组（死循环）,netty推荐使用两个线程组
    	//不断从客户端获取连接，但不做处理，接收到客户端消息后发送给worker
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        //处理连接逻辑
        EventLoopGroup workerGroup = new NioEventLoopGroup();
    	try {
    		ServerBootstrap serverBootstrap = new ServerBootstrap();
            serverBootstrap.group(bossGroup, workerGroup)
            				.channel(NioServerSocketChannel.class)
            				.childHandler(new TestServerInitializer());
            
            ChannelFuture channeluture = serverBootstrap.bind(8899).sync();
            channeluture.channel().closeFuture().sync();
            System.err.println("----------->");
    	}finally {
			bossGroup.shutdownGracefully();
			workerGroup.shutdownGracefully();
		}
    }
}
